﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using DanaZhangCms.Services;
using DanaZhangCms.Domain.SiteXml;
using Microsoft.AspNetCore.Authorization;
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace DanaZhangCms.Areas.SysAdmin.Controllers
{
    [Area("SysAdmin")]
     [Authorize("Admin")]
    public class WebConfigController : Controller
    {
        // GET: /<controller>/
        public IActionResult Index()
        {
            var filePath = System.IO.Path.Combine(GlobalConfiguration.ApplicationPath, "XmlConfig", "site.config");
            var site = DanaZhangCms.Helper.XmlHelper.XmlDeserializeFromFile<Site>(filePath, System.Text.Encoding.UTF8);
            return View(site);
        }
        [HttpPost]
        public IActionResult Index(Site model)
        {
            var filePath = System.IO.Path.Combine(GlobalConfiguration.ApplicationPath, "XmlConfig", "site.config");
            DanaZhangCms.Helper.XmlHelper.XmlSerializeToFile(model,filePath, System.Text.Encoding.UTF8);
            return View(model);
        }
    }
}
